﻿@using Compass.Wasm.Shared.Categories
@using Compass.Wasm.Shared.Data
@using Compass.Wasm.Shared.Projects
@inject HttpClient Http
@inject IJSRuntime JsRuntime
<td>
    @if (_model != null)
    {
        @*todo:如果添加了数据，则点击链接进入，否则在旁边点击添加数据*@
        @if (Module.IsModuleDataOk)
        {
            <a href="update/@_model.Name/@Module.Id">
                <span style="font-weight: bold">@Module.Name</span>
                <span>（@_model.Name-@_modelType.Name）</span>
            </a>
        }
        else
        {
            <span style="font-weight: bold">@Module.Name</span>
            <span>（@_model.Name-@_modelType.Name）</span>
        }
        
    }
    @if (!string.IsNullOrWhiteSpace(Module.SpecialNotes))
    {
        foreach (var note in Module.SpecialNotes.Split('\n'))
        {
            <br />
            <span class="mx-2" style="color: blue">@note</span>
        }
    }
</td>
<td>
    @if (Module.IsModuleDataOk)
    {
        <span>@_moduleData.Length x @_moduleData.Width x @_moduleData.Height</span>
    }
</td>
@code {
    [Parameter]
    public ModuleDto Module { get; set; }

    private ModelDto? _model=new();
    private ModelTypeDto? _modelType=new();
    private string _userName=string.Empty;
    private ModuleData? _moduleData = new();
    protected override async Task OnInitializedAsync()
    {
        _modelType = await Http.GetFromJsonAsync<ModelTypeDto>($"api/ModelType/{Module.ModelTypeId}");
        _model = await Http.GetFromJsonAsync<ModelDto>($"api/Model/{_modelType.ModelId}");
        _userName = await Http.GetStringAsync($"api/Drawing/UserName/{Module.DrawingId}");
        if (Module.IsModuleDataOk)
        {
            _moduleData = await Http.GetFromJsonAsync<ModuleData>($"api/Data/{Module.Id}");
            if (_moduleData!=null) _moduleData.ChangeId(Module.Id.Value);
        }
    }
}
